/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wangxin
 * Date: 2025-01-19
 * Time: 22:31
 */
class MyCircularQueue {
    public int[] elem;
    public int front;
    public int rear;
    public int usedSize;
    public MyCircularQueue(int capacity) {
        elem = new int[capacity + 1];
    }
    //入队
    public boolean enQueue(int value) {
        if(isFull()) {
            return false;
        }
        elem[rear] = value;
        rear= (rear+1)%elem.length;
        usedSize++;
        return true;
    }
    //出队
    public int deQueue() {
        if(isEmpty()) {
            return -1;
        }
        int ret = elem[front];
        front= (front+1)%elem.length;
        usedSize--;
        return ret;
    }
    //得到队头元素
    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return elem[front];
    }
    //获取队列容量
    public int size(){
        return usedSize;
    }
    //判断队列是否为空
    public boolean isEmpty() {
        return front== rear;
    }

    // 判断队列是否为满
    public boolean isFull() {
        return (rear+ 1) % elem.length == front;
    }
}
